package day1;

import java.util.Objects;

/**
 * ClassName：Student
 *
 * @Author：小鱼
 * @Create：2025-08-11 11:42
 */
public class Student_noorder {
    private String name;
    private int age;

    //属性构造器
    public Student_noorder() {
    }

    public Student_noorder(String name, int age) {
        this.name = name;
        this.age = age;
    }

    //getset方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "\nStudent{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student_noorder student = (Student_noorder) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

//    @Override
//    public int compareTo(Student_noorder o) {
//        //重写的排序方法
//        //name升序调用String本身的排序函数
//        int num = this.name.compareTo(o.name);
//
//        //age降序
//        if(num==0){
//            //当name相同时，age降序排
//           //升序时用它： num = ((Integer)age).compareTo(o.age);
//            num = -((Integer)age).compareTo(o.age);
//
//            //方法二：
//            num = -(age-o.age);
//        }
//
//        return num;
//    }
}
